home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Add-Ons / BBEdit / MacBob 1.0ß2 / Source / CStream.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-07  |  1.8 KB  |  80 lines  |  [TEXT/KAHL]

  1. /***
  2.   *
  3.   *    CStream.h - I/O stream classes BBEdit extensions.
  4.   *    Copyright © 1995 by Christopher E. Hyde.  All rights reserved.
  5.   *
  6.   ***/
  7.  
  8. #pragma once
  9.  
  10. enum {
  11. #ifndef EOF
  12.     EOF                =    -1,
  13. #endif
  14.     kGrowStream        =    8 * 1024,
  15.     kInitStream        =    8 * 1024,
  16.     kInitTempSize    =    256,
  17.     kInputStream    =    false,
  18.     kOutputStream    =    true,
  19.     kOwnsHandle        =    true
  20. };
  21.  
  22.  
  23. struct CStream {
  24.     Handle        fHandle;
  25.     uchar*        fBase;
  26.     UInt32        fLength;
  27.     UInt32        fOffset;
  28.     bool        fDirection;
  29.     bool        fOwnsHandle;
  30.  
  31. //                CStream        (void);
  32. //               ~CStream        (void);
  33.         void    Open        (Handle aHandle, bool direction, bool ownsHandle);
  34.         void    SetLength    (UInt32 length);
  35.         Handle    GetHandle    (void);
  36.         void    Flush        (void);
  37.         void    Close        (void);
  38. inline bool    IsOutput    (void) const { return fDirection; }
  39. inline bool    OwnsHandle    (void) const { return fOwnsHandle; }
  40.  
  41. protected:
  42.     static inline Handle NewHandle (UInt32 size) {
  43.         return BBEdit->Allocate(size, false);
  44.     }
  45. };
  46.  
  47.  
  48. struct CIStream : public CStream {
  49. //            CIStream    (WindowPtr window);
  50. //           ~CIStream    (void);
  51.  
  52.     void    Open        (Handle data, bool ownsHandle)
  53.                             { CStream::Open(data, kInputStream, ownsHandle); }
  54.     void    Open        (WindowPtr window);
  55.     void    Open        (WindowPtr window, long selStart, long selEnd);
  56.     int        Get            (void);
  57.     void    Get            (char* dst, int size);
  58.     int        CurChar        (void) const;
  59.     bool    IsEOF        (void) const { return fOffset >= fLength; }
  60. };
  61.  
  62.  
  63. struct COStream : public CStream {
  64. //            COStream    (UInt32 length);
  65. //           ~COStream    (void);
  66.  
  67.     bool        fAutoFlush;    // Automatically flush each write
  68.  
  69.     void    Open        (bool autoFlush = false, UInt32 length = kInitStream);
  70.     void    Put            (char ch);
  71.     void    Put            (const char* ptr, UInt32 length);
  72.     void    Put            (ConstStr255Param aString);
  73.     void    Put            (const char* str);
  74.     void    NewLine        (void);
  75. };
  76.  
  77.  
  78. #define    Min(a, b)        (((a) < (b)) ? (a) : (b))
  79. #define    Max(a, b)        (((a) > (b)) ? (a) : (b))
  80.